package drds.configuration.db.xml_mapping.dynamic_tag.tag;


import drds.configuration.db.xml_mapping.dynamic_tag.tag_context.TagContext;

public class IfTag implements Tag {
    private final ExpressionEvaluator expressionEvaluator;
    private final String test;
    /**
     * 如果test=true,则执行tag里面的内容
     */
    private final Tag tag;

    public IfTag(Tag tag, String test) {
        this.expressionEvaluator = new ExpressionEvaluator();
        this.test = test;
        this.tag = tag;
    }

    @Override
    public boolean apply(TagContext tagContext) {
        if (expressionEvaluator.evaluateBoolean(test, tagContext.getTagContextMap())) {
            tag.apply(tagContext);
            return true;
        }
        return false;
    }

}
